import { defineApplicationConfig } from '@vben/vite-config';
import Inspector from 'vite-plugin-vue-inspector';

export default defineApplicationConfig({
  overrides: {
    optimizeDeps: {
      include: [
        'echarts/core',
        'echarts/charts',
        'echarts/components',
        'echarts/renderers',
        'qrcode',
        '@iconify/iconify',
        'ant-design-vue/es/locale/zh_CN',
        'ant-design-vue/es/locale/en_US',
        'ant-design-vue/es/locale/ja_JP',
        'ant-design-vue/es/locale/zh_TW',
        'vxe-table/lib/locale/lang/zh-CN',
        'vxe-table/lib/locale/lang/en-US',
        'vxe-table/lib/locale/lang/ja-JP',
        'vxe-table/lib/locale/lang/zh-TW',
      ],
    },
    server: {
      https: undefined,
      // Listening on all local IPs
      host: true,
      port: 38061,
      /** 代理设置列表 */
      proxy: {
        '/api': {
          target: 'http://127.0.0.1:38062',
          changeOrigin: false,
          ws: true,
          // rewrite: (path) => path.replace(new RegExp(`^/api`), ''),
          rewrite: (path) => path,
          // !only https
          // secure: false,
          // !解决页面跳转模式下参数丢失的问题。
          bypass: (req: any, _res: any, _options: any) => {
            req.url = (req as any)?.originalUrl || req.url;
          },
        },
        '/signin-': {
          target: 'http://127.0.0.1:38062',
          changeOrigin: false,
          ws: true,
          rewrite: (path) => path,
          // !解决页面跳转模式下参数丢失的问题。
          bypass: (req: any, _res: any, _options: any) => {
            req.url = (req as any)?.originalUrl || req.url;
          },
        },
        '/signalr': {
          target: 'http://127.0.0.1:38062',
          changeOrigin: false,
          ws: true,
          rewrite: (path) => path,
          // !解决页面跳转模式下参数丢失的问题。
          bypass: (req: any, _res: any, _options: any) => {
            req.url = (req as any)?.originalUrl || req.url;
          },
        },
        '/files': {
          target: 'http://127.0.0.1:38062',
          changeOrigin: false,
          ws: true,
          rewrite: (path) => path,
          // !解决页面跳转模式下参数丢失的问题。
          bypass: (req: any, _res: any, _options: any) => {
            req.url = (req as any)?.originalUrl || req.url;
          },
        },
        '/upload': {
          target: 'http://127.0.0.1:38062/api/file',
          changeOrigin: false,
          ws: true,
          rewrite: (path) => path,
          // !解决页面跳转模式下参数丢失的问题。
          bypass: (req: any, _res: any, _options: any) => {
            req.url = (req as any)?.originalUrl || req.url;
          },
        },
      },
      open: false, // 项目启动后，自动打开
      warmup: {
        clientFiles: ['./index.html', './src/{views,components}/*'],
      },
    },
    plugins: [
      Inspector({
        openInEditorHost: 'http://localhost:38061',
      }),
    ],
  },
});
